<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"      
      >
    <h:head>             <meta http-equiv="expires" content="0"></meta>             <meta http-equiv="Cache-Control" content="no-cache"></meta>             <meta http-equiv="Cache-Control" content="no-cache"></meta>
        <title>.:DMES:. - Cargue de Documentos por Usuario</title>
        <script type="text/javascript">
            function start() {
                PF('statusDialog').show();
            }

            function stop() {
                PF('statusDialog').hide();
            }
            window.setTimeout("documentByUserInit()",500);
        </script>
    </h:head>
    <h:body>
        <p:ajaxStatus onstart="PF('statusDialog').show()" oncomplete="PF('statusDialog').hide()"/>
            <p:dialog modal="true" widgetVar="statusDialog" header="Cargando..."
                      draggable="false" closable="false" resizable="false">
                <p:graphicImage value="/images/loadBar.gif"/>
            </p:dialog>
        <div>

<!--         Dialogo para guardar nuevos roles         -->
        <p:dialog id="dialogSaveDocuments" widgetVar="dialogSaveDocuments" position="center top" 
                      closable="true" draggable="true" dynamic="true" header="Subir un Documento"
                      hideEffect="explode" modal="true" showEffect="explode" resizable="true">
                <h:form id="formSaveScDocument" enctype="multipart/form-data">
                    
                    <table width="98%" cellspacing="30">
                        <tr>
                            <td width="20%" align="right">
                                <p:outputLabel  for="tfTittle" value="Título del Documento:"/>
                            </td>
                            <td width="80%" align="left">
                                <p:inputText    id="tfTittle"  value="#{fsDocumentsByUserBean.scDocumentsAdd.documentTittle}"
                                                />
                            </td>
                        </tr> 
                        <tr>
                            <td width="20%" align="right">
                                <p:outputLabel  for="fuLoadFile" value="Archivo:"/>
                            </td>
                            <td width="80%" align="left" >
                                <p:fileUpload label="Examinar"  id="fuLoadFile" mode="simple" 
                                              value="#{fsDocumentsByUserBean.upLoadFile}" 
                                              update="messagesFU,tfTittle"
                                              />   
                                
                            </td>
                        </tr>
                        <tr>
                            <td width="20%" align="center" colspan="2">
                                <p:commandButton id="btnLoadDocument" value="Cargar" icon="ui-icon-circle-arrow-s"
                                                 ajax="false" actionListener="#{fsDocumentsByUserBean.handleFileUpload()}"
                                                 oncomplete="PF('dialogSaveDocuments').hide()"/>
                                <p:spacer width="30"/>
                                <p:commandButton id="btnClean" value="Cancelar" icon="ui-icon-circle-close"
                                                 ajax="false" actionListener="#{fsDocumentsByUserBean.cleanFieldSave()}"
                                                 oncomplete="PF('dialogSaveDocuments').hide()"/>
                            </td>
                        </tr>
                    </table> 
                </h:form>
            </p:dialog> 
<!--         finaliza el dialogo para guardar roles               -->
            <p:growl autoUpdate="true" showDetail="true" life="8000" />
            <h:form id="formDocumentsByUser">
                <p:remoteCommand name="documentByUserInit" update=":formDocumentsByUser:fsDocumentsByUser" />
                <p:dataTable id="fsDocumentsByUser" draggableColumns="true" emptyMessage="No existe información para visualizar" 
                         value="#{fsDocumentsByUserBean.documentList}" var="documents"
                         paginator="true" rows="10"  
                         pageLinks="40"
                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} 
                         {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                         rowKey="#{documents.idDocument}"
                         resizableColumns="true" selection="#{fsDocumentsByUserBean.scDocumentsSelected}"
                         liveResize="true" rowsPerPageTemplate="10,20,30" 
                         selectionMode="single" paginatorPosition="top"
                         sortBy="#{documents.idDocument}">
                <f:facet name="header">
                    <p:commandButton icon="ui-icon-plus" id="btnAdd" style="float: right;"  
                    oncomplete="PF('dialogSaveDocuments').show()">
                        <p:tooltip for="btnAdd" value="Cargar un Documento"/>
                    </p:commandButton>
                </f:facet>
                
                    
                    <p:column id="columnTittle" headerText="Título" sortBy="#{documents.documentTittle}" filterBy="#{documents.documentTittle}" filterMatchMode="contains">    
                    <center>
                        <p:outputLabel value="#{documents.documentTittle}"/>
                    </center>
                    </p:column>
                    <p:column id="columnDocument" headerText="Documento" sortBy="#{documents.documentName}" filterBy="#{documents.documentName}" filterMatchMode="contains">    
                    <center>
                        <p:outputLabel value="#{documents.documentName}"/>
                    </center>
                    </p:column>
                    <p:column id="columnDate" headerText="Fecha de Creación" sortBy="#{fsDocumentsByUserBean.getFormatDate(documents.creationDate)}" 
                              filterBy="#{fsDocumentsByUserBean.getFormatDate(documents.creationDate)}" filterMatchMode="contains">    
                    <center>
                        <p:outputLabel value="#{fsDocumentsByUserBean.getFormatDate(documents.creationDate)}" />
                    </center>
                    </p:column>
                    <p:column id="columnUser" headerText="Subido por" sortBy="#{documents.uploadBy}" filterBy="#{documents.uploadBy}" filterMatchMode="contains">    
                    <center>
                        <p:outputLabel value="#{documents.uploadBy}"/>
                    </center>
                    </p:column>
                    <p:column headerText="Admin" width="84" >
                    <center>
                        <p:commandButton icon="ui-icon-arrowthickstop-1-s" id="btnDownload" 
                                         actionListener="#{fsDocumentsByUserBean.downloadDocument(documents)}"
                                         ajax="false" onstart="start()" oncomplete="stop()">
                            <p:tooltip for="btnDownload" value="Descargar Documento"/>
                        </p:commandButton>
                        <p:spacer width="10"/>
                        <p:commandButton icon="ui-icon-close" id="btnDelete" 
                                         actionListener="#{fsDocumentsByUserBean.deleteDocument(documents)}"
                                         update="fsDocumentsByUser">
                            <p:tooltip for="btnDelete" value="Eliminar Documento"/>
                        </p:commandButton>
                    </center>
                    </p:column>
            </p:dataTable>
            </h:form>
        </div>
        
    </h:body>
</html>

